<!--
Copyright (c) 2019-2026, Hossein Moein
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
  notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in the
  documentation and/or other materials provided with the distribution.
* Neither the name of Hossein Moein and/or the DataFrame nor the
  names of its contributors may be used to endorse or promote products
  derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Hossein Moein BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<!DOCTYPE html>
<html>

<head>
<style>
body {
  background-image: linear-gradient(Azure, AliceBlue, GhostWhite, WhiteSmoke);
}
</style>
</head>

<body style="font-family: Georgia, serif">

  <font size="+3">&#8592;</font> <a href="https://htmlpreview.github.io/?https://github.com/hosseinmoein/DataFrame/blob/master/docs/HTML/DataFrame.html">Back to Documentations</a><BR><BR>
  
  <table border="1">

    <tr bgcolor="lightblue">
      <th>Signature</th> <th>Description</th>
    </tr>
    <tr bgcolor="Azure">
      <td>
<pre class="code_syntax" style="color:#000000;background:#ffffff00;"><span class="line_wrapper"><span style="color:#800000; font-weight:bold; ">enum</span> <span style="color:#800000; font-weight:bold; ">class</span> impurity_type <span style="color:#800080; ">:</span> <span style="color:#800000; font-weight:bold; ">unsigned</span> <span style="color:#800000; font-weight:bold; ">char</span>  <span style="color:#800080; ">{</span></span>
<span class="line_wrapper">    <span style="color:#696969; ">// Measure how often a randomly chosen element from the set would be</span></span>
<span class="line_wrapper">    <span style="color:#696969; ">// incorrectly labeled</span></span>
<span class="line_wrapper">    <span style="color:#696969; ">// Gini = 1 - &#8721;P<sub>i</sub><sup>2</sup></span></span>
<span class="line_wrapper">    <span style="color:#696969; ">//</span></span>
<span class="line_wrapper">    gini_index <span style="color:#808030; ">=</span> <span style="color:#008c00; ">1</span><span style="color:#808030; ">,</span></span>
<span class="line_wrapper"></span>
<span class="line_wrapper">    <span style="color:#696969; ">// Average level of "information", "surprise", or "uncertainty" inherent</span></span>
<span class="line_wrapper">    <span style="color:#696969; ">// to the variable's possible outcomes.</span></span>
<span class="line_wrapper">    <span style="color:#696969; ">// Entropy = -&#8721;P<sub>i</sub> log<sub>2</sub>(P<sub>i</sub>)</span></span>
<span class="line_wrapper">    <span style="color:#696969; ">//</span></span>
<span class="line_wrapper">    info_entropy <span style="color:#808030; ">=</span> <span style="color:#008c00; ">2</span><span style="color:#808030; ">,</span></span>
<span class="line_wrapper"><span style="color:#800080; ">}</span><span style="color:#800080; ">;</span></span>
<span class="line_wrapper"></span></pre>
      </td>
      <td>
        Impurity type
      </td>
    </tr>

  </table>

    <BR>

  <table border="1">

    <tr bgcolor="lightblue">
      <th>Signature</th> <th>Description</th> <th>Parameters</th>
    </tr>
    <tr bgcolor="Azure">
      <td>
<pre class="code_syntax" style="color:#000000;background:#ffffff00;"><span class="line_wrapper"><span style="color:#004a43; ">#</span><span style="color:#004a43; ">include </span><span style="color:#800000; ">&lt;</span><span style="color:#40015a; ">DataFrame/DataFrameMLVisitors.h</span><span style="color:#800000; ">&gt;</span></span>
<span class="line_wrapper"></span>
<span class="line_wrapper"><span style="color:#800000; font-weight:bold; ">template</span><span style="color:#800080; ">&lt;</span><span style="color:#800000; font-weight:bold; ">typename</span> T<span style="color:#808030; ">,</span> <span style="color:#800000; font-weight:bold; ">typename</span> I <span style="color:#808030; ">=</span> <span style="color:#800000; font-weight:bold; ">unsigned</span> <span style="color:#800000; font-weight:bold; ">long</span><span style="color:#808030; ">,</span></span>
<span class="line_wrapper">         <span style="color:#666616; ">std</span><span style="color:#800080; ">::</span><span style="color:#603000; ">size_t</span> A <span style="color:#808030; ">=</span> <span style="color:#008c00; ">0</span><span style="color:#800080; ">&gt;</span></span>
<span class="line_wrapper"><span style="color:#800000; font-weight:bold; ">struct</span> EntropyVisitor<span style="color:#800080; ">;</span></span>
<span class="line_wrapper"></span>
<span class="line_wrapper"><span style="color:#696969; ">// -------------------------------------</span></span>
<span class="line_wrapper"></span>
<span class="line_wrapper"><span style="color:#800000; font-weight:bold; ">template</span><span style="color:#800080; ">&lt;</span><span style="color:#800000; font-weight:bold; ">typename</span> T<span style="color:#808030; ">,</span> <span style="color:#800000; font-weight:bold; ">typename</span> I <span style="color:#808030; ">=</span> <span style="color:#800000; font-weight:bold; ">unsigned</span> <span style="color:#800000; font-weight:bold; ">long</span><span style="color:#808030; ">,</span></span>
<span class="line_wrapper">         <span style="color:#666616; ">std</span><span style="color:#800080; ">::</span><span style="color:#603000; ">size_t</span> A <span style="color:#808030; ">=</span> <span style="color:#008c00; ">0</span><span style="color:#800080; ">&gt;</span></span>
<span class="line_wrapper"><span style="color:#800000; font-weight:bold; ">using</span> ent_v <span style="color:#808030; ">=</span> EntropyVisitor<span style="color:#800080; ">&lt;</span>T<span style="color:#808030; ">,</span> I<span style="color:#808030; ">,</span> A<span style="color:#800080; ">&gt;</span><span style="color:#800080; ">;</span></span>
<span class="line_wrapper"></span></pre>
      </td>
      <td>
        This is a "single action visitor", meaning it is passed the whole data vector in one call and you must use the single_act_visit() interface.<BR><BR>
        This visitor calculates the rolling values of information entropy<BR>
        In information theory, the entropy of a random variable is the average level of "information", "surprise", or "uncertainty" inherent in the variable's possible outcomes. The concept of information entropy was introduced by Claude Shannon in his 1948 paper.<BR>
        A die has higher entropy (p=1/6) versus a coin (p=1/2).<BR>
        This method is an approximation and not as computationally intensive as the method below.<BR>
        <I>
        <PRE>
    explicit
    EntropyVisitor(std::size_t roll_count, T log_base = 2);
        </PRE>
        </I>
      </td>
      <td width="30%">
        <B>T</B>: Column data type.<BR>
        <B>I</B>: Index type.<BR>
        <B>A</B>: Memory alignment boundary for vectors. Default is system default alignment<BR>
      </td>
    </tr>

    <tr bgcolor="Azure">
      <td>
<pre class="code_syntax" style="color:#000000;background:#ffffff00;"><span class="line_wrapper"><span style="color:#004a43; ">#</span><span style="color:#004a43; ">include </span><span style="color:#800000; ">&lt;</span><span style="color:#40015a; ">DataFrame/DataFrameMLVisitors.h</span><span style="color:#800000; ">&gt;</span></span>
<span class="line_wrapper"></span>
<span class="line_wrapper"><span style="color:#800000; font-weight:bold; ">template</span><span style="color:#800080; ">&lt;</span><span style="color:#800000; font-weight:bold; ">typename</span> T<span style="color:#808030; ">,</span> <span style="color:#800000; font-weight:bold; ">typename</span> I <span style="color:#808030; ">=</span> <span style="color:#800000; font-weight:bold; ">unsigned</span> <span style="color:#800000; font-weight:bold; ">long</span><span style="color:#808030; ">,</span></span>
<span class="line_wrapper">         <span style="color:#666616; ">std</span><span style="color:#800080; ">::</span><span style="color:#603000; ">size_t</span> A <span style="color:#808030; ">=</span> <span style="color:#008c00; ">0</span><span style="color:#800080; ">&gt;</span></span>
<span class="line_wrapper"><span style="color:#800000; font-weight:bold; ">struct</span> ImpurityVisitor<span style="color:#800080; ">;</span></span>
<span class="line_wrapper"></span>
<span class="line_wrapper"><span style="color:#696969; ">// -------------------------------------</span></span>
<span class="line_wrapper"></span>
<span class="line_wrapper"><span style="color:#800000; font-weight:bold; ">template</span><span style="color:#800080; ">&lt;</span><span style="color:#800000; font-weight:bold; ">typename</span> T<span style="color:#808030; ">,</span> <span style="color:#800000; font-weight:bold; ">typename</span> I <span style="color:#808030; ">=</span> <span style="color:#800000; font-weight:bold; ">unsigned</span> <span style="color:#800000; font-weight:bold; ">long</span><span style="color:#808030; ">,</span></span>
<span class="line_wrapper">         <span style="color:#666616; ">std</span><span style="color:#800080; ">::</span><span style="color:#603000; ">size_t</span> A <span style="color:#808030; ">=</span> <span style="color:#008c00; ">0</span><span style="color:#800080; ">&gt;</span></span>
<span class="line_wrapper"><span style="color:#800000; font-weight:bold; ">using</span> impu_v <span style="color:#808030; ">=</span> ImpurityVisitor<span style="color:#800080; ">&lt;</span>T<span style="color:#808030; ">,</span> I<span style="color:#808030; ">,</span> A<span style="color:#800080; ">&gt;</span><span style="color:#800080; ">;</span></span>
<span class="line_wrapper"></span></pre>
      </td>
      <td>
        This is a "single action visitor", meaning it is passed the whole data vector in one call and you must use the single_act_visit() interface.<BR><BR>
        This visitor calculates the rolling impurity of the data column.<BR>
        Decision trees recursively split features with regard to their target variable's purity. The algorithm is designed to find the optimal point of the most predictive feature in order to split 1 dataset into 2. These 2 new datasets' target variable will be more pure than the original dataset's.<BR>
"Pure" is the key word here, however. What does that word mean, exactly? In a general sense "purity" can be thought of as how homogenized a group is. But homogeneity can mean different things depending on which mathematical backbone your decision tree runs on. The 2 most popular backbones for decision tree's decisions are Gini Index and Information Entropy.<BR><BR>
        This method is computationally intensive. It dynamically finds the probability of each feature during each rolling period and applies the formula for the selected method.<BR>
        Type <I>T</I> must be hash-able<BR>
        <I>
        <PRE>
    ImpurityVisitor(size_type roll_count, impurity_type it);
        </PRE>
        </I>
      </td>
      <td width="30%">
        <B>T</B>: Column data type.<BR>
        <B>I</B>: Index type.<BR>
        <B>A</B>: Memory alignment boundary for vectors. Default is system default alignment<BR>
      </td>
    </tr>

  </table>

<pre style='color:#000000;background:#ffffff00;'><span style='color:#800000; font-weight:bold; '>static</span> <span style='color:#800000; font-weight:bold; '>void</span> test_EntropyVisitor<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span>  <span style='color:#800080; '>{</span>

    <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>cout</span> <span style='color:#808030; '>&lt;</span><span style='color:#808030; '>&lt;</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\n</span><span style='color:#0000e6; '>Testing EntropyVisitor{  } ...</span><span style='color:#800000; '>"</span> <span style='color:#808030; '>&lt;</span><span style='color:#808030; '>&lt;</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>endl</span><span style='color:#800080; '>;</span>

    <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>vector</span><span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>unsigned</span> <span style='color:#800000; font-weight:bold; '>long</span><span style='color:#800080; '>></span>  idx <span style='color:#808030; '>=</span>
        <span style='color:#800080; '>{</span> <span style='color:#008c00; '>123450</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>123451</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>123452</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>123453</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>123454</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>123455</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>123456</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>123457</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>123458</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>123459</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>123460</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>123461</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>123462</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>123466</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>123467</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>123468</span><span style='color:#808030; '>,</span>
          <span style='color:#008c00; '>123469</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>123470</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>123471</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>123472</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>123473</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>22</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>23</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>24</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>25</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>26</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>27</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>28</span>
        <span style='color:#800080; '>}</span><span style='color:#800080; '>;</span>
    <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>vector</span><span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>double</span><span style='color:#800080; '>></span>         close <span style='color:#808030; '>=</span>
        <span style='color:#800080; '>{</span> <span style='color:#008000; '>1.80</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>2.80</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>1.90</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>14.00</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>1.10</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>6.00</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>13.00</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>8.00</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>9.00</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>2.80</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>1.90</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>4.30</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>20.00</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>1.85</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>3.00</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>34.00</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>67.00</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>23.00</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>87.00</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>9.00</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>45.00</span><span style='color:#808030; '>,</span>
          <span style='color:#008000; '>1.00</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>11.00</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>456.00</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>34.00</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>7.00</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>7778.00</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>5.00</span>
        <span style='color:#800080; '>}</span><span style='color:#800080; '>;</span>
    MyDataFrame                 df<span style='color:#800080; '>;</span>

    df<span style='color:#808030; '>.</span>load_data<span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>move</span><span style='color:#808030; '>(</span>idx<span style='color:#808030; '>)</span><span style='color:#808030; '>,</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span>make_pair<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>close</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> close<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    EntropyVisitor<span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>double</span><span style='color:#800080; '>></span>  e_v <span style='color:#808030; '>(</span><span style='color:#008c00; '>5</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    df<span style='color:#808030; '>.</span>single_act_visit<span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>double</span><span style='color:#800080; '>></span><span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>close</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> e_v<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    assert<span style='color:#808030; '>(</span>e_v<span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>.</span>size<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span> <span style='color:#808030; '>=</span><span style='color:#808030; '>=</span> <span style='color:#008c00; '>28</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    assert<span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span>isnan<span style='color:#808030; '>(</span>e_v<span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>[</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>]</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    assert<span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span>isnan<span style='color:#808030; '>(</span>e_v<span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>[</span><span style='color:#008c00; '>7</span><span style='color:#808030; '>]</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    assert<span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>abs</span><span style='color:#808030; '>(</span>e_v<span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>[</span><span style='color:#008c00; '>8</span><span style='color:#808030; '>]</span> <span style='color:#808030; '>-</span> <span style='color:#008000; '>2.18974</span><span style='color:#808030; '>)</span> <span style='color:#808030; '>&lt;</span> <span style='color:#008000; '>0.00001</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    assert<span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>abs</span><span style='color:#808030; '>(</span>e_v<span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>[</span><span style='color:#008c00; '>10</span><span style='color:#808030; '>]</span> <span style='color:#808030; '>-</span> <span style='color:#008000; '>1.98477</span><span style='color:#808030; '>)</span> <span style='color:#808030; '>&lt;</span> <span style='color:#008000; '>0.00001</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    assert<span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>abs</span><span style='color:#808030; '>(</span>e_v<span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>[</span><span style='color:#008c00; '>14</span><span style='color:#808030; '>]</span> <span style='color:#808030; '>-</span> <span style='color:#008000; '>1.7154</span><span style='color:#808030; '>)</span> <span style='color:#808030; '>&lt;</span> <span style='color:#008000; '>0.0001</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    assert<span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>abs</span><span style='color:#808030; '>(</span>e_v<span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>[</span><span style='color:#008c00; '>27</span><span style='color:#808030; '>]</span> <span style='color:#808030; '>-</span> <span style='color:#008000; '>0.596666</span><span style='color:#808030; '>)</span> <span style='color:#808030; '>&lt;</span> <span style='color:#008000; '>0.00001</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    assert<span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>abs</span><span style='color:#808030; '>(</span>e_v<span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>[</span><span style='color:#008c00; '>25</span><span style='color:#808030; '>]</span> <span style='color:#808030; '>-</span> <span style='color:#008000; '>0.822228</span><span style='color:#808030; '>)</span> <span style='color:#808030; '>&lt;</span> <span style='color:#008000; '>0.00001</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    assert<span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>abs</span><span style='color:#808030; '>(</span>e_v<span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>[</span><span style='color:#008c00; '>22</span><span style='color:#808030; '>]</span> <span style='color:#808030; '>-</span> <span style='color:#008000; '>1.49397</span><span style='color:#808030; '>)</span> <span style='color:#808030; '>&lt;</span> <span style='color:#008000; '>0.0001</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>
</pre>
<!--Created using ToHtml.com on 2021-01-07 19:33:30 UTC -->

<!-- HTML generated using hilite.me --><div style="background: #ffffff00; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #888888">// -----------------------------------------------------------------------------</span>

<span style="color: #008800; font-weight: bold">static</span> <span style="color: #333399; font-weight: bold">void</span> <span style="color: #0066BB; font-weight: bold">test_ImpurityVisitor</span>()  {

    std<span style="color: #333333">::</span>cout <span style="color: #333333">&lt;&lt;</span> <span style="background-color: #fff0f0">&quot;</span><span style="color: #666666; font-weight: bold; background-color: #fff0f0">\n</span><span style="background-color: #fff0f0">Testing ImpurityVisitor{  } ...&quot;</span> <span style="color: #333333">&lt;&lt;</span> std<span style="color: #333333">::</span>endl;

    StlVecType<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">unsigned</span> <span style="color: #333399; font-weight: bold">long</span><span style="color: #333333">&gt;</span>   idx <span style="color: #333333">=</span>
        { <span style="color: #0000DD; font-weight: bold">123450</span>, <span style="color: #0000DD; font-weight: bold">123451</span>, <span style="color: #0000DD; font-weight: bold">123452</span>, <span style="color: #0000DD; font-weight: bold">123453</span>, <span style="color: #0000DD; font-weight: bold">123454</span>, <span style="color: #0000DD; font-weight: bold">123455</span>, <span style="color: #0000DD; font-weight: bold">123456</span>, <span style="color: #0000DD; font-weight: bold">123457</span>, <span style="color: #0000DD; font-weight: bold">123458</span>, <span style="color: #0000DD; font-weight: bold">123459</span>, <span style="color: #0000DD; font-weight: bold">123460</span>, <span style="color: #0000DD; font-weight: bold">123461</span>, <span style="color: #0000DD; font-weight: bold">123462</span>, <span style="color: #0000DD; font-weight: bold">123466</span>,
          <span style="color: #0000DD; font-weight: bold">123467</span>, <span style="color: #0000DD; font-weight: bold">123468</span>, <span style="color: #0000DD; font-weight: bold">123469</span>, <span style="color: #0000DD; font-weight: bold">123470</span>, <span style="color: #0000DD; font-weight: bold">123471</span>, <span style="color: #0000DD; font-weight: bold">123472</span>, <span style="color: #0000DD; font-weight: bold">123473</span> };
    StlVecType<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>     metal <span style="color: #333333">=</span> { <span style="background-color: #fff0f0">&quot;Gold&quot;</span>, <span style="background-color: #fff0f0">&quot;Gold&quot;</span>, <span style="background-color: #fff0f0">&quot;Gold&quot;</span>, <span style="background-color: #fff0f0">&quot;Gold&quot;</span> };
    StlVecType<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>     metal2 <span style="color: #333333">=</span> { <span style="background-color: #fff0f0">&quot;Gold&quot;</span>, <span style="background-color: #fff0f0">&quot;Silver&quot;</span>, <span style="background-color: #fff0f0">&quot;Silver&quot;</span>, <span style="background-color: #fff0f0">&quot;Gold&quot;</span> };
    StlVecType<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span>          numbers <span style="color: #333333">=</span>
        { <span style="color: #6600EE; font-weight: bold">2.5</span>, <span style="color: #6600EE; font-weight: bold">2.5</span>, <span style="color: #6600EE; font-weight: bold">2.5</span>, <span style="color: #333333">-</span><span style="color: #6600EE; font-weight: bold">0.1</span>, <span style="color: #333333">-</span><span style="color: #6600EE; font-weight: bold">1.1</span>, <span style="color: #333333">-</span><span style="color: #6600EE; font-weight: bold">0.1</span>, <span style="color: #333333">-</span><span style="color: #6600EE; font-weight: bold">1.1</span>, <span style="color: #333333">-</span><span style="color: #6600EE; font-weight: bold">1.1</span>, <span style="color: #333333">-</span><span style="color: #6600EE; font-weight: bold">0.1</span>, <span style="color: #6600EE; font-weight: bold">34.5</span>, <span style="color: #333333">-</span><span style="color: #6600EE; font-weight: bold">1.1</span>,
          <span style="color: #6600EE; font-weight: bold">34.5</span>, <span style="color: #6600EE; font-weight: bold">34.5</span>, <span style="color: #6600EE; font-weight: bold">34.5</span>, <span style="color: #6600EE; font-weight: bold">0.123</span>, <span style="color: #6600EE; font-weight: bold">0.123</span>, <span style="color: #6600EE; font-weight: bold">0.123</span>, <span style="color: #6600EE; font-weight: bold">0.5</span>, <span style="color: #6600EE; font-weight: bold">0.4</span>, <span style="color: #6600EE; font-weight: bold">2.5</span>, <span style="color: #6600EE; font-weight: bold">0.5</span> };
    MyDataFrame                 df;

    df.load_data(std<span style="color: #333333">::</span>move(idx), std<span style="color: #333333">::</span>make_pair(<span style="background-color: #fff0f0">&quot;Numbers&quot;</span>, numbers));
    df.load_column(<span style="background-color: #fff0f0">&quot;Metals&quot;</span>, std<span style="color: #333333">::</span>move(metal), nan_policy<span style="color: #333333">::</span>dont_pad_with_nans);
    df.load_column(<span style="background-color: #fff0f0">&quot;Metals2&quot;</span>, std<span style="color: #333333">::</span>move(metal2), nan_policy<span style="color: #333333">::</span>dont_pad_with_nans);

    impu_v<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span> impu (<span style="color: #0000DD; font-weight: bold">4</span>, impurity_type<span style="color: #333333">::</span>gini_index);
    <span style="color: #008800; font-weight: bold">const</span> <span style="color: #008800; font-weight: bold">auto</span>          result <span style="color: #333333">=</span> df.single_act_visit<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>(<span style="background-color: #fff0f0">&quot;Metals&quot;</span>, impu).get_result();

    assert(result.size() <span style="color: #333333">==</span> <span style="color: #0000DD; font-weight: bold">1</span>);
    assert(result[<span style="color: #0000DD; font-weight: bold">0</span>] <span style="color: #333333">==</span> <span style="color: #0000DD; font-weight: bold">0</span>);

    impu_v<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span> impu2 (<span style="color: #0000DD; font-weight: bold">4</span>, impurity_type<span style="color: #333333">::</span>info_entropy);
    <span style="color: #008800; font-weight: bold">const</span> <span style="color: #008800; font-weight: bold">auto</span>          result2 <span style="color: #333333">=</span> df.single_act_visit<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>(<span style="background-color: #fff0f0">&quot;Metals&quot;</span>, impu2).get_result();

    assert(result2.size() <span style="color: #333333">==</span> <span style="color: #0000DD; font-weight: bold">1</span>);
    assert(result2[<span style="color: #0000DD; font-weight: bold">0</span>] <span style="color: #333333">==</span> <span style="color: #0000DD; font-weight: bold">0</span>);

    impu_v<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span> impu3 (<span style="color: #0000DD; font-weight: bold">4</span>, impurity_type<span style="color: #333333">::</span>gini_index);
    <span style="color: #008800; font-weight: bold">const</span> <span style="color: #008800; font-weight: bold">auto</span>          result3 <span style="color: #333333">=</span> df.single_act_visit<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>(<span style="background-color: #fff0f0">&quot;Metals2&quot;</span>, impu3).get_result();

    assert(result3.size() <span style="color: #333333">==</span> <span style="color: #0000DD; font-weight: bold">1</span>);
    assert(result3[<span style="color: #0000DD; font-weight: bold">0</span>] <span style="color: #333333">==</span> <span style="color: #6600EE; font-weight: bold">0.5</span>);

    impu_v<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span> impu4 (<span style="color: #0000DD; font-weight: bold">4</span>, impurity_type<span style="color: #333333">::</span>info_entropy);
    <span style="color: #008800; font-weight: bold">const</span> <span style="color: #008800; font-weight: bold">auto</span>          result4 <span style="color: #333333">=</span> df.single_act_visit<span style="color: #333333">&lt;</span>std<span style="color: #333333">::</span>string<span style="color: #333333">&gt;</span>(<span style="background-color: #fff0f0">&quot;Metals2&quot;</span>, impu4).get_result();

    assert(result4.size() <span style="color: #333333">==</span> <span style="color: #0000DD; font-weight: bold">1</span>);
    assert(result4[<span style="color: #0000DD; font-weight: bold">0</span>] <span style="color: #333333">==</span> <span style="color: #6600EE; font-weight: bold">1.0</span>);

    impu_v<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span>  impu5 (<span style="color: #0000DD; font-weight: bold">3</span>, impurity_type<span style="color: #333333">::</span>gini_index);
    <span style="color: #008800; font-weight: bold">const</span> <span style="color: #008800; font-weight: bold">auto</span>      result5 <span style="color: #333333">=</span> df.single_act_visit<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span>(<span style="background-color: #fff0f0">&quot;Numbers&quot;</span>, impu5).get_result();

    assert(result5.size() <span style="color: #333333">==</span> <span style="color: #0000DD; font-weight: bold">19</span>);
    assert(result5[<span style="color: #0000DD; font-weight: bold">0</span>] <span style="color: #333333">==</span> <span style="color: #0000DD; font-weight: bold">0</span>);
    assert(fabs(result5[<span style="color: #0000DD; font-weight: bold">1</span>] <span style="color: #333333">-</span> <span style="color: #6600EE; font-weight: bold">0.4444</span>) <span style="color: #333333">&lt;</span> <span style="color: #6600EE; font-weight: bold">0.0001</span>);
    assert(fabs(result5[<span style="color: #0000DD; font-weight: bold">2</span>] <span style="color: #333333">-</span> <span style="color: #6600EE; font-weight: bold">0.6667</span>) <span style="color: #333333">&lt;</span> <span style="color: #6600EE; font-weight: bold">0.0001</span>);
    assert(fabs(result5[<span style="color: #0000DD; font-weight: bold">3</span>] <span style="color: #333333">-</span> <span style="color: #6600EE; font-weight: bold">0.4444</span>) <span style="color: #333333">&lt;</span> <span style="color: #6600EE; font-weight: bold">0.0001</span>);
    assert(fabs(result5[<span style="color: #0000DD; font-weight: bold">4</span>] <span style="color: #333333">-</span> <span style="color: #6600EE; font-weight: bold">0.4444</span>) <span style="color: #333333">&lt;</span> <span style="color: #6600EE; font-weight: bold">0.0001</span>);
    assert(fabs(result5[<span style="color: #0000DD; font-weight: bold">18</span>] <span style="color: #333333">-</span> <span style="color: #6600EE; font-weight: bold">0.6667</span>) <span style="color: #333333">&lt;</span> <span style="color: #6600EE; font-weight: bold">0.0001</span>);
    assert(fabs(result5[<span style="color: #0000DD; font-weight: bold">17</span>] <span style="color: #333333">-</span> <span style="color: #6600EE; font-weight: bold">0.6667</span>) <span style="color: #333333">&lt;</span> <span style="color: #6600EE; font-weight: bold">0.0001</span>);
    assert(fabs(result5[<span style="color: #0000DD; font-weight: bold">16</span>] <span style="color: #333333">-</span> <span style="color: #6600EE; font-weight: bold">0.6667</span>) <span style="color: #333333">&lt;</span> <span style="color: #6600EE; font-weight: bold">0.0001</span>);
    assert(fabs(result5[<span style="color: #0000DD; font-weight: bold">15</span>] <span style="color: #333333">-</span> <span style="color: #6600EE; font-weight: bold">0.4444</span>) <span style="color: #333333">&lt;</span> <span style="color: #6600EE; font-weight: bold">0.0001</span>);
    assert(result5[<span style="color: #0000DD; font-weight: bold">14</span>] <span style="color: #333333">==</span> <span style="color: #0000DD; font-weight: bold">0</span>);
    assert(fabs(result5[<span style="color: #0000DD; font-weight: bold">13</span>] <span style="color: #333333">-</span> <span style="color: #6600EE; font-weight: bold">0.4444</span>) <span style="color: #333333">&lt;</span> <span style="color: #6600EE; font-weight: bold">0.0001</span>);

    impu_v<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span>  impu6 (<span style="color: #0000DD; font-weight: bold">3</span>, impurity_type<span style="color: #333333">::</span>info_entropy);
    <span style="color: #008800; font-weight: bold">const</span> <span style="color: #008800; font-weight: bold">auto</span>      result6 <span style="color: #333333">=</span> df.single_act_visit<span style="color: #333333">&lt;</span><span style="color: #333399; font-weight: bold">double</span><span style="color: #333333">&gt;</span>(<span style="background-color: #fff0f0">&quot;Numbers&quot;</span>, impu6).get_result();

    assert(result6.size() <span style="color: #333333">==</span> <span style="color: #0000DD; font-weight: bold">19</span>);
    assert(result6[<span style="color: #0000DD; font-weight: bold">0</span>] <span style="color: #333333">==</span> <span style="color: #0000DD; font-weight: bold">0</span>);
    assert(fabs(result6[<span style="color: #0000DD; font-weight: bold">1</span>] <span style="color: #333333">-</span> <span style="color: #6600EE; font-weight: bold">0.9183</span>) <span style="color: #333333">&lt;</span> <span style="color: #6600EE; font-weight: bold">0.0001</span>);
    assert(fabs(result6[<span style="color: #0000DD; font-weight: bold">2</span>] <span style="color: #333333">-</span> <span style="color: #6600EE; font-weight: bold">1.585</span>) <span style="color: #333333">&lt;</span> <span style="color: #6600EE; font-weight: bold">0.0001</span>);
    assert(fabs(result6[<span style="color: #0000DD; font-weight: bold">3</span>] <span style="color: #333333">-</span> <span style="color: #6600EE; font-weight: bold">0.9183</span>) <span style="color: #333333">&lt;</span> <span style="color: #6600EE; font-weight: bold">0.0001</span>);
    assert(fabs(result6[<span style="color: #0000DD; font-weight: bold">4</span>] <span style="color: #333333">-</span> <span style="color: #6600EE; font-weight: bold">0.9183</span>) <span style="color: #333333">&lt;</span> <span style="color: #6600EE; font-weight: bold">0.0001</span>);
    assert(fabs(result6[<span style="color: #0000DD; font-weight: bold">18</span>] <span style="color: #333333">-</span> <span style="color: #6600EE; font-weight: bold">1.585</span>) <span style="color: #333333">&lt;</span> <span style="color: #6600EE; font-weight: bold">0.0001</span>);
    assert(fabs(result6[<span style="color: #0000DD; font-weight: bold">17</span>] <span style="color: #333333">-</span> <span style="color: #6600EE; font-weight: bold">1.585</span>) <span style="color: #333333">&lt;</span> <span style="color: #6600EE; font-weight: bold">0.0001</span>);
    assert(fabs(result6[<span style="color: #0000DD; font-weight: bold">16</span>] <span style="color: #333333">-</span> <span style="color: #6600EE; font-weight: bold">1.585</span>) <span style="color: #333333">&lt;</span> <span style="color: #6600EE; font-weight: bold">0.0001</span>);
    assert(fabs(result6[<span style="color: #0000DD; font-weight: bold">15</span>] <span style="color: #333333">-</span> <span style="color: #6600EE; font-weight: bold">0.9183</span>) <span style="color: #333333">&lt;</span> <span style="color: #6600EE; font-weight: bold">0.0001</span>);
    assert(result6[<span style="color: #0000DD; font-weight: bold">14</span>] <span style="color: #333333">==</span> <span style="color: #0000DD; font-weight: bold">0</span>);
    assert(fabs(result6[<span style="color: #0000DD; font-weight: bold">13</span>] <span style="color: #333333">-</span> <span style="color: #6600EE; font-weight: bold">0.9183</span>) <span style="color: #333333">&lt;</span> <span style="color: #6600EE; font-weight: bold">0.0001</span>);
}
</pre></div>

  <BR><img src="https://github.com/hosseinmoein/DataFrame/blob/master/docs/LionLookingUp.jpg?raw=true" alt="C++ DataFrame"
       width="200" height="200" style="float:right"/>

</body>
</html>

<!--
Local Variables:
mode:HTML
tab-width:4
c-basic-offset:4
End:
-->
